package com.powernode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.powernode.constant.AuthConstants;
import com.powernode.domain.Member;
import com.powernode.mapper.MemberMapper;
import com.powernode.service.MemberService;
import com.powernode.utils.AuthUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {

    @Autowired
    private MemberMapper memberMapper;


    /**
     * 根据OpenId修改会员信息
     *
     * 此方法用于更新数据库中与给定OpenId关联的会员记录
     * 它首先获取当前成员的OpenId，然后使用该信息来更新会员表中的相应记录
     *
     * @param member 包含要更新的会员信息的对象
     * @return 返回一个布尔值，指示是否成功更新了会员信息
     */
    @Override
    public Boolean modifyMemberInfoByOpenId(Member member) {
        // 获取当前会员的OpenId
        String openId = AuthUtils.getMemberOpenId();
        // 更新会员信息，条件是会员的OpenId与获取到的OpenId相等
        int update = memberMapper.update(member, new LambdaQueryWrapper<Member>().eq(Member::getOpenId, openId));
        // 返回更新是否成功的布尔值
        return update > 0;
    }
}
